package com.evolution.model;

import com.evolution.utils.RandomGenerator;

public class OrganismUtils {

	private static final int MUTATION_RATE = 10;
	
	public static Organism birthNewOrganism(Organism parent){
		Organism child = new Organism(parent);
		child.setSize(parent.getSize());
		child.setStingerSize(parent.getStingerSize());
		child.setSpeciesID(parent.getSpeciesID());
		
		if(RandomGenerator.randomBoolean(MUTATION_RATE)){
			mutate(child);
		}
		
		OrganismRegistry.getInstance().registerOrganism(child, parent);
		
		return child;
	}
	
	private static void mutate(Organism organism){
		organism.setSize(RandomGenerator.randomInt(15));
		organism.setStingerSize(RandomGenerator.randomInt(10));
		organism.setSpeciesID(SpeciesUtils.createSpecies().getID());
	}
}
